package com.example.mo131010_2;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	EditText edit01,edit02;
	Button btnadd,btnsub,btnmul,btndiv;
	TextView textresult;
	String num1 , num2;
	int result;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		setTitle("초간단 계산기 ? ");
		
		edit01 = (EditText) findViewById(R.id.edit01);
		edit02 = (EditText) findViewById(R.id.edit02);
		
		btnadd = (Button) findViewById(R.id.btn01);
		btnsub = (Button) findViewById(R.id.btn02);
		btnmul = (Button) findViewById(R.id.btn03);
		btndiv = (Button) findViewById(R.id.btn04);
		
		textresult	= (TextView) findViewById(R.id.txt01);
		
		btnadd.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View arg01, MotionEvent arg02) {
				// TODO Auto-generated method stub
			num1 = edit01.getText().toString();
			num2 = edit02.getText().toString();
			result = Integer.parseInt(num1) + Integer.parseInt(num2);
			textresult.setText("계산결과 : " + num1 + "+"+num2+ " = "+ result);
			return false;
			}
		});
		
		btnsub.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View arg01, MotionEvent arg02) {
				// TODO Auto-generated method stub
			num1 = edit01.getText().toString();
			num2 = edit02.getText().toString();
			result = Integer.parseInt(num1) - Integer.parseInt(num2);
			textresult.setText("계산결과 : " + num1 +"-"+ num2+ " = "+ result);
			return false;
			}
		});

		btnmul.setOnTouchListener(new View.OnTouchListener() {
	
	@Override
			public boolean onTouch(View arg01, MotionEvent arg02) {
				// TODO Auto-generated method stub
			num1 = edit01.getText().toString();
			num2 = edit02.getText().toString();
			result = Integer.parseInt(num1) * Integer.parseInt(num2);
			textresult.setText("계산결과 : " + num1 +"*"+ num2+ " = "+ result);
			return false;
		}
		});

		btndiv.setOnTouchListener(new View.OnTouchListener() {
	
				@Override
					public boolean onTouch(View arg01, MotionEvent arg02) {
						// TODO Auto-generated method stub
					num1 = edit01.getText().toString();
					num2 = edit02.getText().toString();
					float f = Float.valueOf(num1).floatValue() / Float.valueOf(num2).floatValue();
					textresult.setText("계산결과 : " + num1 +"/"+ num2+ " = "+ f);
					return false;
				}
		});
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
